<template>
	<view class="" style="position:relative;">
		<view class="uni-swiper__warp " :style="{width:swiperHeight + 'rpx'}">
			<view :class="['uni-swiper__navbar', '', !noAbsolute ? 'navabsolut' : '']" :style="'position:' + (!noAbsolute ? 'absolute' : 'relative') + ';'" v-if="!showVideo">
				<text class="f-24 ">{{ '' + swoperCurrent + 1 + '/' + imgInfo.length + (hasVideo && videoExist ? videoInfo.length : 0) + '' }}</text>
			</view>
			<swiper @change="change" class="swiper-box " :current="swoperCurrent" :style="'height:' + swiperHeight + 'rpx' + ';'">
				<swiper-item v-if="videoInfo.length > 0 && hasVideo && videoExist">
					<view @tap="clickToWatchVideo" class="video-item " :style="'height:' + swiperHeight + 'rpx' + ';'">
						<u-image
							borderRadius="25"
							class="img "
							@error="imgError"
							:height="swiperHeight + 'rpx'"
							:lazyLoad="true"
							mode="aspectFill"
							:src="videoInfo[0] + '?x-oss-process=video/snapshot,t_1000,f_jpg,w_0,h_0,m_fast'"
						>
							<u-loading :color="color" size="50" v-slot:loading></u-loading>
						</u-image>
						<view class="cover-img "><image class="" mode="aspectFill" style="width:100rpx;height:100rpx;"></image></view>
					</view>
				</swiper-item>
				<block v-if="imgList.length">
					<swiper-item class="" v-for="(item, index) in imgList" :key="index">
						<view class="swiper-item " @tap="clickTolgimg(index)">
							<u-image borderRadius="25" class="img " :height="swiperHeight + 'rpx'" :width="swiperHeight + 'rpx'" :lazyLoad="true" mode="aspectFill" :src="item">
								<u-loading :color="color" size="50" v-slot:loading></u-loading>
							</u-image>
						</view>
					</swiper-item>
				</block>
			</swiper>
		</view>
		<view class="mask-video " :style="'height:' + swiperHeight + 'rpx' + ';'" v-if="showVideo">
			<video autoplay="true" class="video " objectFit="contain" :src="videoInfo[0]" :style="'height:' + swiperHeight + 'rpx' + ';'">
				<cover-image class="cover " @tap="exitVideo"></cover-image>
			</video>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		imgInfo: {
			type: Array,
			default: function() {
				return [];
			}
		},
		videoExist: {
			type: Boolean,
			default: !1
		},
		videoInfo: {
			type: Array,
			default: function() {
				return [];
			}
		},
		noAbsolute: {
			type: Boolean,
			defalut: !1
		},
		current: {
			type: [Number, String],
			default: 0
		},
		navType: {
			type: String,
			default: ''
		},
		toUrl: {
			type: String,
			default: ''
		},
		swiperHeight: {
			type: [Number, String],
			default: 694
		},
		color: {
			type: String,
			default: '#c7c7c7'
		}
	},
	data: function() {
		return {
			showVideo: !1,
			hasVideo: !0,
			imgList: [],
			swoperCurrent: 0
		};
	},
	watch: {
		imgInfo: {
			deep: !0,
			immediate: !0,
			handler: function(e) {
				var t = this;
				(this.showVideo = !1),
					(this.imgList = []),
					this.$nextTick(function() {
						t.imgList = e;
					});
			}
		},
		current: {
			deep: !0,
			immediate: !0,
			handler: function(e) {
				this.$nextTick(function() {
					this.swoperCurrent = e;
				});
			}
		}
	},
	methods: {
		imgError: function(e) {
			console.log('imgError ---\x3e', e), (this.hasVideo = !1);
		},
		change: function(e) {
			this.$emit('changeIndex', e.detail.current);
		},
		clickTolgimg: function(e) {
			this.$emit('postIndex', e);
		},
		clickToWatchVideo: function() {
			this.showVideo = !0;
		},
		exitVideo: function() {
			this.showVideo = !1;
		}
	}
};
</script>

<style>
.mask-video {
	background: #000;
	overflow: hidden;
	position: absolute;
	top: 0;
}

.mask-video,
.mask-video .video {
	border-radius: 25rpx;
	width: 100%;
}

.cover {
	color: #fff;
	font-size: 32rpx;
	height: 100rpx;
	left: 0rpx;
	position: absolute;
	top: 16rpx;
	width: 100rpx;
}

.uni-swiper__warp {
	border-radius: 25rpx;
	overflow: hidden;
	position: relative;
	margin: 0 auto;
}

.uni-swiper__warp .swiper-box,
.uni-swiper__warp .swiper-box .swiper-item {
	border-radius: 25rpx;
	overflow: hidden;
	width: 100%;
	transform: translateY(0);
}

.uni-swiper__warp .swiper-box .swiper-item .img {
	border-radius: 25rpx;
	width: 100%;
	justify-content: center;
}

.uni-swiper__warp .swiper-box .video-item {
	background-color: #000;
	border-radius: 25rpx;
	overflow: hidden;
	position: relative;
	width: 100%;
}

.uni-swiper__warp .swiper-box .video-item .img {
	border-radius: 25rpx;
	width: 100%;
}

.uni-swiper__warp .swiper-box .video-item .cover-img {
	align-items: center;
	border-radius: 25rpx;
	bottom: 0;
	display: flex;
	justify-content: center;
	left: 0;
	position: absolute;
	right: 0;
	top: 0;
}

.uni-swiper__navbar {
	height: 35rpx;
	line-height: 35rpx;
	text-align: center;
	z-index: 50;
}

.uni-swiper__navbar.navabsolut {
	background-color: rgba(0, 0, 0, 0.7);
	border-radius: 40rpx;
	bottom: 36rpx;
	color: #fff;
	padding: 0 20rpx;
	right: 44rpx;
}
</style>
